package chuyentrung.racehorses;

import java.util.Random;

import chuyentrung.racehorses.Horse.ColorHorse;
import chuyentrung.racehorses.framework.math.Vector2;

public class World {

	public interface WorldListener {
		public void hit();

		public void tossDice();

		public void move();
	}

	public static final float WORLD_WIDTH = 10;
	public static final float WORLD_HEIGHT = 15 * 20;
	public static final int WORLD_STATE_RUNNING = 0;
	public static final int WORLD_STATE_FINISH = 1;
	public static final Vector2 gravity = new Vector2(0, -12);

	public final Position[] waitPos, racePos;
	public final Position[][] stablePos;
	public final Player[] players;
	public final Dice dice;
	public  WorldListener listener;
	public final Random rand;

	public long time; // unit is second
	public int currPlayerId;
	public int state;
	public int numPlayers;

	public World(WorldListener listener) {
		dice = new Dice(100, 200);
		numPlayers = GamePreferences.numPlayers;
		players = new Player[numPlayers];				
		waitPos = new Position[4];
		racePos = new Position[48];
		stablePos = new Position[4][6];	
		this.listener = listener;
		rand = new Random();
		generateWorld();
		
		time = 0;
		state = WORLD_STATE_RUNNING;
	}

	public void generateWorld() {
		for (int i = 0; i < 4; i++)
			waitPos[i] = new Position();
		for (int i = 0; i < 4; i++)
			racePos[i] = new Position();
		for (int i = 0; i < 4; i++)
			for (int j = 0; j < 6; j++)
				stablePos[i][j] = new Position();
		for (int i = 0; i < numPlayers; i++)
			players[i] = new Player(GamePreferences.typeHorse[i]);
	}

	public int nextPlayer() {
		currPlayerId += 1;
		return currPlayerId;
	}

}
